import App from './App'
import uView from '@/uni_modules/uview-ui'
import upload from 'common/setting.vue'
import Vue from 'vue'
import mixins from 'common/mixins.js'
import Common from "@/units/Common";

const oss = (url) => {
	if(!url) {
		return url
	}
	if (typeof url === 'string') {
		if ((/^(http|https):\/\/.+/.test(url))) {

			return url
		} else {
			http://banshi.bomei.club  测试
			// https://www.stck.cc
			return 'https://qn.stck.cc' + url
		}
	} else {
		let arr = []
		for (let i = 0; i < url.length; i++) {
			if ((/^(http|https):\/\/.+/.test(url))) {
				arr.push(url)
			} else {
				arr.push('https://qn.stck.cc/api' + url)
			}
		}
		return arr
	}


}
const back = () => {
	uni.$u.route({
		type: 'back'
	})
}


const authTo = (url) => {
	if (uni.getStorageSync('token')) {
		uni.$u.route({
			url: url
		})
	} else {
		uni.$u.route({
			url: 'pagesA/auth/login'
		})
	}
}
const article = (type, title) => {
	uni.$u.route({
		url: 'pages/my/setting/article',
		params: {
			type: type,
			title
		}
	})
}

const copy = (content) => {
	uni.setClipboardData({
		data: content,
		success: function() {
			uni.$u.toast('复制成功')
		},
		fail: function() {
			uni.$u.toast('复制失败')
		}
	});
}
const goto = (url) => {
	uni.$u.route({
		url: url
	})
}

const toast = (word) => {
	uni.$u.toast(word);
}

Vue.prototype.oss = oss
Vue.prototype.back = back
Vue.prototype.copy = copy
Vue.prototype.article = article
Vue.prototype.authTo = authTo
Vue.prototype.goto = goto
Vue.prototype.toast = toast
Vue.config.productionTip = false
Vue.prototype.Upload = upload
Vue.prototype.$Common = Common
Vue.mixin(mixins)
App.mpType = 'app'


const app = new Vue({
	...App
})
require('@/common/http.interceptor.js')(app)
Vue.use(uView)
app.$mount()
